package org.zhangsh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.net.URL;
import java.nio.charset.StandardCharsets;

/**
 * Hello world!
 */
@SpringBootApplication
@RestController
@EnableWebMvc
public class App {

    @Autowired
    private RestTemplate restTemplate;

    public static void main(String[] args) {

//        SpringApplication.run(App.class);

        System.out.println(Runtime.getRuntime().availableProcessors());
    }

    @GetMapping("/index")
    public void send(){

        String urlStr = "http://10.124.210.174:9999/jtauditwo/prj/wsrs/endauditcost/addCostDetail/12345";

//        URL url = new URL();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        httpHeaders.add("Authorization", "token");
        HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
        ResponseEntity<String> result = restTemplate.postForEntity(urlStr, httpEntity, String.class);

        System.out.println(new String(result.getBody().getBytes(), StandardCharsets.UTF_8));
    }
}
